package com.example.demo.controller;

import com.example.demo.entity.Product;
import com.example.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/products")
public class ProductController {
    @Autowired
    private ProductService productService;

    @PostMapping
    public Product save(@RequestBody Product product) {
        return productService.save(product);
    }

    @PutMapping
    public Product update(@RequestBody Product product) {
        return productService.update(product);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable int id) {
        productService.delete(id);
    }

    @GetMapping("/fa-num/{faNum}")
    public List<Product> findByFaNum(@PathVariable int faNum) {
        return productService.findByFaNum(faNum);
    }

    @GetMapping("/shou-num/{shouNum}")
    public List<Product> findByShouNum(@PathVariable int shouNum) {
        return productService.findByShouNum(shouNum);
    }
}
